from django.db import models

# Create your models here.
from base_model import BaseModel


class GoodsCategory(BaseModel):
    name = models.CharField(max_length=100, verbose_name='名称')
    sequence = models.IntegerField(default=1, verbose_name='顺序')
    picture = models.FileField(null=True, blank=True, verbose_name='图片')

    class Meta:
        db_table = 'goods_category'
        verbose_name = '商品种类'
        verbose_name_plural = verbose_name


class Goods(BaseModel):
    name = models.CharField(max_length=200, null=True, blank=True, verbose_name='名字')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='售价')
    category = models.ForeignKey(GoodsCategory, on_delete=models.CASCADE, related_name='goods', verbose_name='种类')
    cost_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='进价')
    desc = models.TextField(null=True, blank=True, verbose_name='描述')
    stock = models.IntegerField(default=0, verbose_name='库存')
    sales = models.IntegerField(default=0, verbose_name='销量')
    is_launched = models.BooleanField(verbose_name='是否上架出售', default=False)

    class Meta:
        db_table = 'goods'
        verbose_name = '商品'
        verbose_name_plural = verbose_name


class GoodsPicture(BaseModel):
    """允许轮播图"""
    picture = models.FileField(verbose_name='图片')
    sequence = models.IntegerField(default=1, null=True, blank=True, verbose_name='顺序')
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE, related_name='picture', verbose_name='商品')

    class Meta:
        db_table = 'goods_picture'
        verbose_name = '商品图片'
        verbose_name_plural = verbose_name


class GoodsSpecification(BaseModel):
    name = models.CharField(max_length=50, verbose_name='名称')
    key = models.CharField(max_length=50, verbose_name='规格值')
    goods = models.ForeignKey(Goods, on_delete=models.CASCADE, related_name='specification', verbose_name='商品')

    class Meta:
        db_table = 'goods_specification'
        verbose_name = '商品规格'
        verbose_name_plural = verbose_name
